﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppServidor
{
    class BibliotecaLista
    {
        public static List<Lista> bibliotecaListas;
        public static List<string> allpistas;
        public static void eliminar_lista(string nombre) {

            // Delete a file by using File class static method...
            if (System.IO.File.Exists(@"C:\FistProjectOLC2\Lists\"+nombre+".bin"))
            {
                // Use a try block to catch IOExceptions, to
                // handle the case of the file already being
                // opened by another process.
                try
                {
                    System.IO.File.Delete(@"C:\FistProjectOLC2\Lists\" + nombre + ".bin");
              
                }
                catch (System.IO.IOException e)
                {
                    Console.WriteLine(e.Message);
                    return;
                }
            }
        }
        public static void cargar_data_lista() {
            if (bibliotecaListas == null)
            {
                bibliotecaListas = new List<Lista>();
            }
            else bibliotecaListas.Clear();

            if (allpistas == null)
            {
                allpistas = new List<string>();
            }
            else allpistas.Clear();
           
            System.IO.Directory.CreateDirectory(@"C:\FistProjectOLC2");
            System.IO.Directory.CreateDirectory(@"C:\FistProjectOLC2\Lists");
            System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(@"C:\FistProjectOLC2\Lists");
            System.IO.FileInfo[] fileNames = dirInfo.GetFiles("*.bin");
            foreach (FileInfo file in fileNames) {
                bibliotecaListas.Add(Lista.abrir_archivo(file.Name));
            }
            Lista all = new Lista();
            all.Nombre = "Toda la musica";
            System.IO.Directory.CreateDirectory(@"C:\FistProjectOLC2");
            System.IO.Directory.CreateDirectory(@"C:\FistProjectOLC2\Tracks");
            dirInfo = new System.IO.DirectoryInfo(@"C:\FistProjectOLC2\Tracks");
            fileNames = dirInfo.GetFiles("*.bin");
            foreach (FileInfo file in fileNames)
            {string name=file.Name.Replace(".bin", "");
                all.add(name);
                allpistas.Add(name);
            }
            bibliotecaListas.Add(all);

        }


    }
}
